package shellstation;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;

public class InventoryView extends JFrame implements ActionListener  {

    private JFrame frame;

    private JMenuBar menuBar;

    private JMenu file;

    private JMenuItem mainMenu;
    private JMenuItem logOut;


    private JPanel panel;
    private JPanel panel2;
    private JPanel bluePanel;

    private JLabel shellLabel;
    private JLabel inventoryText;

    private JButton addButton;
    private JButton updateButton;
    private JButton backButton;
    private JButton inventoryButton;

    private Icon addIcon;
    private Icon updateIcon;
    private Icon backIcon;
    private Icon shellIcon;
    private Boolean pressUpdate = false;
    private JButton submit;
    
    private Boolean watcher = false;
    private int z = 0;
    private int yesNo;

    private Color yellow = new Color(255, 218, 63);
    private Color gray = new Color(222,222,222);
    private Color red = new Color(226, 0, 0);
    private Color blue = new Color(62, 142, 169);


    public void InventoryView() {

        addIcon = new ImageIcon(getClass().getResource("image/add.gif"));
        updateIcon = new ImageIcon(getClass().getResource("image/edit.png"));
        backIcon = new ImageIcon(getClass().getResource("image/back.png"));

        shellIcon = new ImageIcon(getClass().getResource("image/box.gif"));

        shellLabel = new JLabel();
        shellLabel.setIcon(shellIcon);
        shellLabel.setBounds(120, 150, 200, 190);

        inventoryText = new JLabel("Inventory");
        inventoryText.setFont(new Font("Hobo Std", Font.BOLD, 28));
        inventoryText.setBounds(120, 10, 225, 50);

        menuBar= new JMenuBar();
        file= new JMenu("File");
        mainMenu= new JMenuItem("Main Menu");
        logOut= new JMenuItem("Log Out");

        mainMenu.addActionListener(this);

        menuBar.add(file);
        file.add(mainMenu);
        file.add(logOut);


        frame = new JFrame("Shell Station - Inventroy Sales System");
        frame.setSize(750, 450);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setJMenuBar(menuBar);

        addButton = new JButton("Add Product");
        addButton.setBackground(gray);
        addButton.setBounds(18, 25, 250, 75);
        addButton.setFont(new Font("Arial", Font.BOLD, 20));
        addButton.addActionListener(this);

        updateButton = new JButton("Update Product");
        updateButton.setBackground(gray);
        updateButton.setBounds(18, 115, 250, 75);
        updateButton.setFont(new Font("Arial", Font.BOLD, 20));
        updateButton.addActionListener(this);

        inventoryButton= new JButton("Inventory Report");
        inventoryButton.setBackground(gray);
        inventoryButton.setBounds(18, 215, 250, 75);
        inventoryButton.setFont(new Font("Arial", Font.BOLD, 20));
        inventoryButton.addActionListener(this);

        backButton= new JButton("Go Back", backIcon);
        backButton.setBackground(gray);
        backButton.setBounds(18, 315, 250, 75);
        backButton.setFont(new Font("Arial", Font.BOLD, 20));
        backButton.addActionListener(this);

        panel = new JPanel(null);
        panel.setBackground(red);

        panel2= new JPanel(null);
        panel2.setBounds(300, 0, 750, 424);
        panel2.setBackground(yellow);

        bluePanel= new JPanel(null);
        bluePanel.setBounds(55, 25, 350, 75);
        bluePanel.setBackground(blue);

        bluePanel.add(inventoryText);

   
        panel.add(addButton);
        panel.add(updateButton);
        panel.add(backButton);
        panel.add(panel2);
        panel.add(inventoryButton);
        panel2.add(shellLabel);

        panel2.add(bluePanel);

        frame.add(panel);
    }

    public void actionPerformed(ActionEvent e){

        if(e.getSource() == addButton){
            if(watcher == true)
            yesNo = JOptionPane.showConfirmDialog(null, "Cancel transaction?", "Confirm cancellation of product", JOptionPane.YES_NO_OPTION);
            
            if(yesNo == JOptionPane.YES_OPTION || watcher == false ){
            AddProductView a = new AddProductView();
            a.AddProductView();
            panel2.removeAll();
            panel2.repaint();
            panel2.add(a.getProductName());
            panel2.add(a.getProductSize());
            panel2.add(a.getNewSize());
            panel2.add(a.getProductPrice());
            panel2.add(a.getProductStock());
            panel2.add(a.getpName());
            panel2.add(a.getbox2());
            panel2.add(a.getnewSize());
            panel2.add(a.getpPrice());
            panel2.add(a.getpStock());
            panel2.add(a.getsubmit());
            panel2.add(a.getProductStatus());
            panel2.add(a.getStatusBox());
            panel2.add(a.getSizeList());
            panel2.add(a.getNewUnit());
            panel2.add(a.getUnitLabel());

            panel2.repaint();
            panel2.revalidate();
            watcher = true;
            }
        }
        else if(e.getSource() == updateButton){
            if(watcher == true)
            yesNo = JOptionPane.showConfirmDialog(null, "Cancel transaction?", "Confirm cancellation of product", JOptionPane.YES_NO_OPTION);
            
            if(yesNo == JOptionPane.YES_OPTION || watcher == false ){
            UpdateProductView up = new UpdateProductView();
                up.UpdateProductView();
                panel2.removeAll();
                panel2.repaint();
                panel2.add(up.getSearchButton());
                panel2.add(up.getscrollPane2());
                panel2.add(up.getsubmit());
                panel2.add(up.getFilter());
                panel2.add(up.getBox());
                panel2.add(up.getSearch());
                panel2.add(up.getSearchField());
                panel2.add(up.getViewAllButton());
                up.setPanel(panel2);

                panel2.repaint();
                panel2.revalidate();
                watcher = true;
            }

        }
       
        else if(e.getSource() == backButton)
        {
            if(watcher == true)
            yesNo = JOptionPane.showConfirmDialog(null, "Cancel transaction?", "Confirm cancellation of product", JOptionPane.YES_NO_OPTION);
            
            if(yesNo == JOptionPane.YES_OPTION || watcher == false ){
            frame.dispose();

            MainMenu m= new MainMenu();
            m.MainMenu();
            watcher = true;
            }
        }

        else if(e.getSource() == inventoryButton){

            if(watcher == true)
            yesNo = JOptionPane.showConfirmDialog(null, "Cancel transaction?", "Confirm cancellation of product", JOptionPane.YES_NO_OPTION);
            
            if(yesNo == JOptionPane.YES_OPTION || watcher == false ){
            InventoryReportView i= new InventoryReportView();
            i.InventoryReportView();
            watcher = true;
            }
        }

        else if(e.getSource() == backButton){
            if(watcher == true)
            yesNo = JOptionPane.showConfirmDialog(null, "Cancel transaction?", "Confirm cancellation of product", JOptionPane.YES_NO_OPTION);
            
            if(yesNo == JOptionPane.YES_OPTION || watcher == false ){

            frame.dispose();
            MainMenu m= new MainMenu();
            m.MainMenu();

            watcher = true;
            }

        }

        else if(e.getSource() == mainMenu){

            if(watcher == true)
            yesNo = JOptionPane.showConfirmDialog(null, "Cancel transaction?", "Confirm cancellation of product", JOptionPane.YES_NO_OPTION);
            
            if(yesNo == JOptionPane.YES_OPTION || watcher == false ){
            frame.dispose();
            MainMenu m= new MainMenu();
            m.MainMenu();
            watcher = true;
            }
        }

      


    }
    
    
}
